// Test: can I pass a pointer to an active ostream, and use it
// for output?
// YES, perfectly.

#include <iostream>
#include <fstream>

std::ostream *stream;

void set_stream(std::ostream& os) {
    stream = &os;
}

void append(int x) {
    (*stream) << x << " ";
}

int main() {
    std::ofstream os;
    os.open("log.txt");

//    stream = &os;
    set_stream(os);

    set_stream(std::cout);

    append(1);
    append(2);
    append(3);

    (*stream) << " (newline here:)\n";

    append(4);
    append(5);
    append(6);

    std::cout << " (newline here:)\n";
}

